package d4_map;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class mapExample {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        Map<String, Integer> map = new HashMap<String, Integer>();

        String[] keys = {"A", "B", "C","D"};//景点集合
        Random rand = new Random();
        for (int i = 0; i < 80; i++) {
            int value = rand.nextInt(4);
            list.add(keys[value]);
        }
        System.out.println(list);

        for (String s: list) {
            if (map.containsKey(s)) {
                map.put(s, map.get(s) + 1);
            }
            else{
                map.put(s, 1);
            }
        }
        System.out.println(map);


    }
}
